package com.item.toyexchange;

/*
 * 玩具详情的界面
 */

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bjtu.toyexchange.R;
import com.request.toyexchange.SendRequest;

public class ToyInfoActivity extends Activity {
	private Button exch, chat, fanhui;
	Integer tid;
	String name, deg, state, detail, tphoto, tuser, user, date;
	TextView nameET, ownerET, degET, stateET, detailET;
	ImageView pic;
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.toy_info);
		
		//得到玩具的名字
		Intent intent = this.getIntent();
		name = intent.getStringExtra("title");
		
		//得到玩具的详细描述，即玩具介绍
		detail = intent.getStringExtra("content");
		//状态
		state = intent.getStringExtra("state");
		//新旧
		deg = intent.getStringExtra("level");
		//玩具所有者
		tuser = intent.getStringExtra("tuser");
		Log.v("tuser",tuser);
		//用户
		user = intent.getStringExtra("user");
		Log.v("user",user);
		//玩具的照片
		tphoto = intent.getStringExtra("tphoto");
		//玩具发布时间
		date = intent.getStringExtra("date");
		Log.v("date",date);
		//玩具id
		tid = intent.getIntExtra("tid", 0);
		
		//设置ImageView
		pic = (ImageView)findViewById(R.id.toy_ima);
		//设置几个Textview的值
		//名字
		nameET = (TextView)findViewById(R.id.toy_name);
		nameET.setText(name);
		//主人
		ownerET = (TextView)findViewById(R.id.toy_owner);
		ownerET.setText(tuser);
		//新旧程度
		degET = (TextView)findViewById(R.id.toy_deg);
		degET.setText(deg);
		//交换状态
		stateET = (TextView)findViewById(R.id.toy_sta);
		stateET.setText(state);
		//详细描述
		detailET = (TextView)findViewById(R.id.toy_det);
		detailET.setText(detail);
		
	    //申请交换玩具的按钮
		exch = (Button)findViewById(R.id.exch_toy);
		exch.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent();
				intent.putExtra("username", user);  //ua_name
				intent.putExtra("ub_name", tuser);  //ub_name
				intent.putExtra("tb_id", tid);  //tb_id
				intent.setClass(ToyInfoActivity.this, SendRequest.class);
				ToyInfoActivity.this.startActivity(intent);
			}
		});
		
		//与主人联系的按钮
		chat = (Button)findViewById(R.id.chat_owner);
		chat.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Toast.makeText(ToyInfoActivity.this, "联系。。.", 200).show();
			}
		});
		
		//返回的按钮
		fanhui = (Button)findViewById(R.id.btnbacktoy);
		fanhui.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				ToyInfoActivity.this.finish();
			}
		});
	}
}
